public class TestDomo {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        swap(a, b);
        System.out.println("main: a = " + a + " b = " + b);
    }
    public static void swap(int x, int y) {
        int tmp = x;
        x = y;
        y = tmp;
        System.out.println("swap: x = " + x + " y = " + y);
    }

    public static int facSum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }
    public static int fac(int n){
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }
    public static void main7(String[] args) {
        int ret = facSum(5);
        System.out.println(ret);
        System.out.println(facSum(6) );
    }
    /**
     * 判断某一年是不是闰年
     * @param year 年份
     * @return true代表是 false代表不是闰年
     */
    public static boolean isLeapYear(int year){
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
            return true;
        }
        return false;
    }
    public static int add(int a,int b){
        return a + b;
    }
    public static void main6(String[] args) {
        int ret = add(1,2);
        System.out.println(ret);
    }
    public static void main5(String[] args) {
        int n = -1;
        int count = 0;
        while (n != 0){
            if ((n&1) != 0) {
                count++;
            }
            n = n>>>1;
        }
        System.out.println(count);
    }

    public static void main4(String[] args) {
        int n = -1;
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if (((n>>>i)&1) != 0) {
                count++;
            }
        }
        System.out.println(count);
    }
    public static void main3(String[] args) {
        for (int i = 1; i < 999_999; i++) {
            int tmp = i;
            int count = 0;//计算i多少位
            while (tmp != 0){
                count++;
                tmp= tmp / 10;
            }
            tmp = i;
            int sum = 0;
            while (tmp != 0){
                sum +=Math.pow(tmp % 10,count);
                tmp /= 10;
            }
            if (sum == i){
                System.out.println(i);
            }
        }
    }
    public static void main2(String[] args) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i + "*" + j + "=" + i*j + " ");
            }
            System.out.println();
        }
    }


    public static void main1(String[] args) {
        for (int n = 1; n <= 100; n++) {
            int i = 2;
            for (; i < Math.sqrt(n); i++) {
                if (n % i == 0) {
                    //System.out.println(n + "不是素数!");
                    break;
                }
            }
            if (i > Math.sqrt(n)) {
                System.out.println(n + "是素数!");
            }
        }
    }
}